<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>告警规则设置</title>
    <meta name="decorator" content="nblank"/>
    <%@include file="/WEB-INF/views/include/treetable.jsp" %>
    <link href="${ctxStatic}/modules/biz/record/equItemHisList.css" rel="stylesheet" itself="true" />
</head>
<body>
<div class="content container">
    <h2 class="page-title">告警规则设置
    </h2>
    <div class="row">
        <div class="col-md-12">
            <section class="widget widget-tabs">
                <header>
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="javascript:;">${officebiz.name}设备列表</a></li>
                    </ul>
                </header>
                <div class="body tab-content">
                    <div class="tab-pane active clearfix" style="position: relative;">
                        <form:form id="inputForm" modelAttribute="condition" method="post" class="form-inline widget">
                            <input type="hidden" id="hiddenOfficeId" value="${officebiz.id}" >
                            <input type="hidden" id="hiddenSgroupId" value="${sgroup.id}">
                            <input type="hidden" id="admin" value="${ctx}"/>

                            <div class="row pd-first">
                                <div class="col-md-4 col-qc-4 git-first" style="display: ${singleStation == 'yes'?'none':'block'}">
                                    <label class="form-group mg-right-10 pull-left"><span style="color: red;">*</span>站点:</label>
                                    <sys:treeselectExtend id="office" name="office.id" value="${officebiz.id}"
                                                    labelName="office.name" labelValue="${officebiz.name}"
                                                    title="站点" url="/sys/office/treeDataThree?type=2"
                                                    cssClass="form-control input-transparent" notAllowSelectRoot="true"
                                                    notAllowSelectParent="false" officeGrade="true"/>
                                </div>
                                <div class="col-md-4 col-qc-4  git-two">
                                    <label class="form-group mg-right-10" for="sgroupId"><span style="color:red;">*</span>组查询:</label>
                                    <form:select path="sgroupId" class="selectpicker" data-style="btn-primary">
                                        <form:option value="" label="请选择"/>
                                    </form:select>
                                </div>
                            </div>
                        </form:form>
                        <div class="widget mg-bottom">
                            <div class="list-box" id="inner-content-div">
                                <table id="mainTable" class="table table-striped  table-condensed tree_table overflow-auto">
                                    <thead>
                                    <tr>
                                        <th>数据显示区</th>
                                    </tr>
                                    </thead>
                                    <tbody class="table-cor">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>
<script type="text/javascript">
    var $sgroup = $("#sgroupId");
    var noData="无数据";
    var admin = $("#admin").val();
    var modify = "规则设置";
    var del = "删除";
    var hiddenOfficeId = $('#hiddenOfficeId').val();
    var hiddenSgroupId =$("#hiddenSgroupId").val();
    $sgroup.attr("disabled", true);
    $sgroup.change().selectpicker('refresh');
    $(function () {
        //用于返回时更新页面
        if(hiddenOfficeId != null && hiddenOfficeId != "" && hiddenSgroupId != null && hiddenSgroupId != ""){
            stationSelect(hiddenOfficeId);
            $("#sgroupId").val(hiddenSgroupId);
            $sgroup.selectpicker('val', hiddenSgroupId);
            $sgroup.change().selectpicker('refresh');
            submitAjax();
        }
//        组查询的change事件
        $('#sgroupId').on('changed.bs.select', function () {
            submitAjax();
        });
    });
    /** jquery 部分结束 */

    /** 表单提交ajax部分 -- 开始 */
    function submitAjax(){
        hiddenOfficeId = $('#officeId').val();
        $.ajax({
            type:"get",
            url:"${ctx}/biz/sgcfg/itemlistById",
            data:{
                sgroupId:$('#sgroupId').val()
            },
            dataType:"json",
            success: function (data) {
                $("#pageDiv").html("");
                $("#mainTable thead").html("");
                $("#mainTable tbody").html("");
                if (data != null && data.length>0) {
                    $("#mainTable thead").append("<tr><th style='width:50%;'>设备名称</th><th>规则设置</th></tr>");
                    $.each(data, function (indexColumn, item) {
                        $("<tr><td>" + item.gitem.name + "</td><td><a href='" + admin + "/biz/eiwRule/list?officeId="+hiddenOfficeId+"&sgroupId="+$('#sgroupId').val()+"&itemId=" + item.gitem.id + "'>" + modify + "</a>&nbsp;</td></tr>")
                                .appendTo("#mainTable tbody");
                    });
                } else {
                    $("#mainTable thead").html("");
                    $("<tr><td align='center'>" + noData + "</td></tr>").appendTo("#mainTable tbody");
                }
            }
        });
    }
    /** 表单提交ajax部分 -- 结束 */

    /** 站点控件选择功能 **/
    function stationSelect(officeIdVar) {
        $sgroup.attr("disabled", true);
        $("#sgroupId option:not(:first)").remove();
        if (officeIdVar == "") {
            $sgroup.change().selectpicker('refresh');
        } else {
            officeIdVar = $('#officeId').val();
            $.ajax({
                type: "post",
                url: "${ctx}/biz/ehRecord/sgroupSelect?officeId=" + officeIdVar,
                dataType: "json",
                async:false ,
                success: function (data) {
                    $.each(data, function (indexColumn, item) {
                        $("<option value='" + item.id + "'>" + item.name + "</option>").appendTo("#sgroupId");
                    });
                    $sgroup.attr("disabled", false);
                    $sgroup.change().selectpicker('refresh');
                }
            });
        }
    }

    <%--function initSgroup(){--%>
        <%--$sgroup.attr("disabled", true);--%>
        <%--$sgroup.find("option:not(:first)").empty();--%>
        <%--$.ajax({--%>
            <%--type: "post",--%>
            <%--url: "${ctx}/biz/eiwRule/sgroupSelect",--%>
            <%--dataType: "json",--%>
            <%--success: function (data) {--%>
                <%--$.each(data, function (indexColumn, item) {--%>
                    <%--$("<option value='" + item.id + "'>" + item.name + "</option>").appendTo("#sgroupId");--%>
                <%--});--%>
                <%--$sgroup.change().selectpicker('refresh');--%>
        <%--}--%>
    <%--});--%>
        <%--$sgroup.attr("disabled", false);--%>
    <%--}--%>


    <%--$(function () {--%>
        <%--if(singleStation=='yes'){--%>
            <%--initSgroup();--%>
        <%--}--%>
    <%--});--%>
</script>
</body>
</html>